unit Ensemble3;

interface
uses
  Classes;

type
  TEnsemble3 = class
  private
    FValuesList : TStringList;
  public
    constructor Create;

    function BestByWeightedRank : Integer;

    property ValuesList : TStringList read FValuesList write FValuesList;

  end;

implementation

uses SysUtils;

{ TEnsemble1 }

function TEnsemble3.BestByWeightedRank: Integer;
var
  i : Integer;

  maior : Double;
  
  a : array[0..9] of Double;

  maiorR : Integer;
begin
  Result := 0;

  for i := 0 to 9 do
    a[i] := 0;

  for i := 0 to FValuesList.Count-1 do
    begin
      a[StrToIntDef(FValuesList.ValueFromIndex[i], 0)] := a[StrToIntDef(FValuesList.ValueFromIndex[i], 0)] + StrToFloatDef(FValuesList.Names[i], 0);
    end;

  maior := 0;

  for i := 0 to 9 do
    begin
      if a[i] > maior then
        begin
          maior := a[i];
          Result := i;
        end;
    end;
  
end;

constructor TEnsemble3.Create;
begin
  FValuesList := TStringList.Create;
end;

end.

